Hi sanguit85,
KFLOP's High speed 8-bit Hardware PWM outputs are only available on KFLOP JP6. They can't be multiplexed to Konnect ouputs.
Have you seen this example of a software PWM and a circuit designed for Konnect Outputs:
You'll need to decide on the hardware you want to use before selecting the software to tie the S command to it.
HTH Regards TK
Group: DynoMotion |
Message: 11968 |
From: sanguit85 |
Date: 7/25/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Tom
1.How do I tie Vout value to S command 2.Would this little RC circuit be enough, or it`s just for example?
|
|
Group: DynoMotion |
Message: 11969 |
From: sanguit85 |
Date: 7/25/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Tom,
1. How do I tie Vout value to S command? 2. Would this little RC circuit be enough, or it`s just an example?
Best regards, Alex
|
|
Group: DynoMotion |
Message: 11972 |
From: TK |
Date: 7/25/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Alex,
The S command can be configured to save the desired RPM as a floating point number into a global persist Variable to be passed to a C Program. Var #113 is commonly used. You can specify a dummy C Program or no Program.
Inside the ServiceKonnectPWM you might constantly read that RPM value into a floating point variable called RPM. Note the C syntax is a bit cryptic because the persist variables are declared as integers. So to fool the C compiler into treating it as a float we take the address of it (&), cast that as a pointer to a float (float *), then dereference the pointer (*) to get the value. Such as:
float RPM=*(float *)&persist.UserData[113];
So now for example if we want the voltage to be 5V when the RPM is 10000.0 we could do:
Vout = RPM * (5.0 / 10000.0);
You will also need to add and call that ServiceKonnectPWM from an infinite loop at the end of your Init program.
Let me know how much you understand.
Regards TK
Hi Tom,
1. How do I tie Vout value to S command? 2. Would this little RC circuit be enough, or it`s just an example?
Best regards, Alex
|
|
Group: DynoMotion |
Message: 11981 |
From: sanguit85 |
Date: 7/26/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Tom I did as you suggested and it works. I have a separate C programm for Spindle Speed, as I wanted to have the opportunity to control it not only from KmotionCNC, but with onboard potentiometer too (not simultaneously, of course), so I did not put the code into INIT file. Now when S-fader in KmotionCNC is on "1" I have 5.5V, when on "2" - I have 10V etc. For this I had to change
Vout = RPM * (5.0 / 10000.0); to Vout = RPM * (5.0 / 1000.0);
Here`s my code, is it correct?
#include "KMotionDef.h"
void ServiceKonnectPWM(void);
double T,T0=0; float Vout=0.0;
main() { float RPM=*(float *)&persist.UserData[113];
for(;;) { T=WaitNextTimeSlice(); ServiceKonnectPWM(); Vout = RPM*(5.0 / 1000.0); } }
#define KMVAR PC_COMM_CSS_S // variable KMotionCNC will pass speed parameter (113) #define C 0.00029f // 1000uF #define R 100.0f // 100 ohms #define Vcc 11.210f // supply voltage #define HIGH_BIT 60 // This output drives Cap high #define LOW_BIT 61 // This output drives Cap low
void ServiceKonnectPWM(void) { static int FirstTime=TRUE; static float Vc=0.0f; static double T0; static int State; double T=Time_sec(); if (FirstTime) { FirstTime=FALSE; T0=T; State=0; } else { float V,I; // Compute Voltage applied to Cap V=Vcc*State; // Compute current I=(V-Vc)/R;
// Compute new Cap Voltage Vc += I/C*(T-T0); // determine next state if (Vc > Vout) { ClearBit(HIGH_BIT); SetBit(LOW_BIT); State=0; } else { ClearBit(LOW_BIT); SetBit(HIGH_BIT); State=1; }
T0=T; // save time when applied } }
|
|
Group: DynoMotion |
Message: 11984 |
From: Tom Kerekes |
Date: 7/26/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi sanguit85,
Sorry I don't understand what you are trying to do. How would you have it controlled both by a potentiometer and the KMotionCNC screen? How would you decide which has control?
Regardless it seems like the loop could be added to the Init program.
The persist variable reference is outside of the loop. Therefore it would only update when the program is restarted. I guess you realize that but I don't understand why.
Regards TK
Group: DynoMotion |
Message: 11986 |
From: baltar.chris |
Date: 7/26/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
I also have a WJ200 granted it is not configured for use on the KFLOP, however if you want it to work in that mode you need to download Hitachi software and program the WJ200 so that the speed input will come from the on board potentiometer or an external potentiometer they have a kit for external control pad. I dont remember if there was a setting within the WJ200 that would let you have the best of both worlds. As I think they could conflict, why would you want to be able to use both? Really your G code would dictate this every time.
Regards -Chris
|
|
Group: DynoMotion |
Message: 11990 |
From: sanguit85 |
Date: 7/27/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Tom Thank you very much for your help. Everything is very simple - I made a little switch inside VFD (instead of jumper), which lets you choose where you control spindle speed from - either with onboard potentiometer or from outboard 0-10V source (KmotionCNC screen for my case).
By the way, I found this function in many hobby-class CNC routers (at least Chinese ones). Maybe it`s unnecessary, but too much control is never enough :)
That`s why I want the "KmotionCNC-Controlling-Spindle-Speed" function to be a separate C programm, assigned to a User Button in KmotionCNC, and not a part of my INIT file. When I`ll want the spinde speed to be controlled from software - I`ll activate that VFD switch and push the button with this C programm in KmotionCNC - in other cases I`ll leave that switch and button alone and will control speed with potentiometer.
Is my code OK for that method? Not sure I understand what you wrote "...The persist variable reference is outside of the loop. Therefore it would only update when the program is restarted." - my C-skills are almost zero....
Best regards, Alex
|
|
Group: DynoMotion |
Message: 11994 |
From: Tom Kerekes |
Date: 7/27/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Alex,
The switch on the jumper sounds like a good idea and should work. But I still don't understand the desire or need for adding the User Button. And doing that way would mean that the speed wouldn't ever change until after you push the User Button again. So for example GCode S commands or moving the SSO slider wouldn't change the speed. If you add the code to a loop in your INIT program it would always be active. In either case your switch and pot could override whatever KMotionCNC is trying to do.
In C Language a loop can be created with a "for" statement like:
for (;;) { xxxxxxx xxxxxxx xxxxxxx }
In this case the stuff between the curly brackets is forever repeated over and over. Stuff before the "for" statement is only executed once.
HTH
Regards TK
Group: DynoMotion |
Message: 11997 |
From: sanguit85 |
Date: 7/27/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Tom Now things are much clearer. Should I put the whole code into infinite loop (somewhere at the end of my INIT) or only some part of it? I mean which commands of the code must repeat forever (or all) to avoid problems you`ve mentioned? (I do realize that the whole code must be in INIT, the question is about which part of it should loop forever)
Best Regards, Alex
|
|
Group: DynoMotion |
Message: 11999 |
From: Tom Kerekes |
Date: 7/27/2015 |
Subject: Re: Another VFD/Spindle Speed control question |
Hi Alex,
I would put all the related Spindle Speed code (reading the RPM from the persist Var set by KMotionCNC, computing the desired Voltage, Toggling the PWM output to generate that voltage, etc) into the ServiceKonnectPWM function. Then make a call to that function from within the "for" loop. Do you understand the concept of functions? It is basically a subroutine. The idea is that in the future you may want to service multiple things in the loop for example maybe an MPG, or monitor external buttons, or EStop, etc... This allows grouping of related code into specific named functions to make things easier to understand rather than mixing multiple conceptual things together in a long list. So then you might end up with a loop to do everything that looks like:
for(;;) { WaitNextTimeSlice(); ServiceKonnectPWM(); ServiceMPG(); ServiceExternalButtons(); ServiceEStop(); }
of course you will need to create each of those functions with the appropriate code to do whatever needs to be performed. Within a C Program file you can organize the functions in any order you wish. I like to put functions toward the end of the program with the main program towards the top. When doing this the compiler likes to have a clue that there is a function, what its name is, what parameters might be passed to it, and if/what the function might return before it sees a call made to the function. The clue to the compiler has the form of the function itself except with no body (just terminated with a semicolon). These are called function prototypes and should be placed somewhere towards the beginning of the file before any executable code. In this case it is the line:
void ServiceKonnectPWM(void);
This just informs to the compiler that if is sees a function call like ServiceKonnectPWM(); that it is a valid call to something coming later, that has no parameters passed in, and nothing is returned from it.
See if the attached program makes sense.
HTH Regards TK
| | | | | | | |